package com.wang.sort;

import java.util.ArrayList;
import java.util.List;

public class TreeTest {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1,
                new TreeNode(2,
                        new TreeNode(4, null, null),
                        new TreeNode(5, null, null)
                ),
                new TreeNode(3,
                        new TreeNode(6, null, null),
                        new TreeNode(7, null, null)
                )
        );
        loopDeep(root);
        loopFor(root);
    }

    public static void loopDeep(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }
        System.out.println(treeNode.value);
        loopDeep(treeNode.left);
        loopDeep(treeNode.right);
    }

    public static void loopFor(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }
        List<TreeNode> ls = new ArrayList<>();
        ls.add(treeNode);
        while (!ls.isEmpty()) {
            System.out.println(treeNode.value);
            if (treeNode.left != null) {
                ls.add(treeNode.left);
            }
            if (treeNode.right != null) {
                ls.add(treeNode.right);
            }
        }
    }
}
